package org.jeecg.modules.flowable.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.flowable.common.dic.ResultMessage;
import org.jeecg.modules.flowable.common.util.validation.AssertValid;
import org.jeecg.modules.flowable.dic.AttType;
import org.jeecg.modules.flowable.service.action.ActionBody;
import org.jeecg.modules.flowable.service.action.ActionFactory;
import org.jeecg.modules.flowable.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Title:  <br>
 * Desc:  <br>
 * Date: 6/21/22 11:33 AM <br>
 * Company: 联通（辽宁）产业互联网有限公司 <br>
 *
 * @author zxd
 * @version 1.0.0
 */
@Api(value = "ActionController", tags = {"(module-flowable)-流程处理-执行动作"})
@ApiSort(value = 1)
@RestController
@RequestMapping("/ActionController")
@Slf4j
public class ActionController {


    @Autowired
    private ActionFactory actionFactory;

    @ApiOperation(value = "流程继续", notes = "流程继续")
    @RequestMapping(path = "/submit", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> submit(@RequestBody ActionBody argActionBody) {
        actionFactory.deal("Submit",argActionBody,null,"继续");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "流程中止", notes = "流程中止")
    @RequestMapping(path = "/stop", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> stop(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        argActionBody.setAttrList(null);
        argActionBody.setFormData(null);
        argActionBody.setAttType(AttType.STOP);
        if(AssertValid.isEmpty(argActionBody.getAttDesc()))
            argActionBody.setAttDesc("流程中止");
        actionFactory.deal("Stop",argActionBody,null,"中止");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "流程回退", notes = "流程回退")
    @RequestMapping(path = "/fallback", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> fallback(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        argActionBody.setAttrList(null);
        argActionBody.setFormData(null);
        actionFactory.deal("Fallback",argActionBody,null,"回退");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "流程撤消", notes = "流程撤消")
    @RequestMapping(path = "/undo", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> undo(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        argActionBody.setAttrList(null);
        argActionBody.setFormData(null);
        actionFactory.deal("Undo",argActionBody,null,"撤消");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "回退致发起者", notes = "回退致发起者")
    @RequestMapping(path = "/backToInitiate", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> backToInitiate(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        argActionBody.setAttrList(null);
        argActionBody.setFormData(null);
        actionFactory.deal("BackToInitiate",argActionBody,null,"回退致发起");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "上报", notes = "上报")
    @RequestMapping(path = "/commit", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> commit(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        actionFactory.deal("Commit",argActionBody,null,"上报");
        return Result.OK(ResultMessage.OK);
    }
    @ApiOperation(value = "处置", notes = "处置")
    @RequestMapping(path = "/deal", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> deal(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        actionFactory.deal("Deal",argActionBody,null,"处置");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "驳回", notes = "驳回")
    @RequestMapping(path = "/back", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> back(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        actionFactory.deal("Back",argActionBody,null,"驳回");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "交办", notes = "交办")
    @RequestMapping(path = "/assigned", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> assigned(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        actionFactory.deal("Assigned",argActionBody,null,"交办");
        return Result.OK(ResultMessage.OK);
    }

    @ApiOperation(value = "撤回", notes = "撤回")
    @RequestMapping(path = "/backToInit", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> backToInit(@RequestBody ActionBody argActionBody) {
        // 注入自定义事件，跟据业务实际情况进行注入
        argActionBody.setActionParam(null);
        actionFactory.deal("BackToInit",argActionBody,null,"撤回");
        return Result.OK(ResultMessage.OK);
    }
}